/*------------------------------------------------------
                hou_elearningGEN beta v1.0
Author: xtrung.net@gmail.com
Write On: 04/27/2008
Create On:4/13/2012 11:22:55 AM
------------------------------------------------------*/
using hou_elearning.DataAccess.Base;
using hou_elearning.Entity;
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections.Generic;
using System.Collections;
using System.Web;

namespace hou_elearning.DataAccess
{    
    public class DanhmuctainguyenDAL : SqlProvider<DanhmuctainguyenEntity>
    {
        static DanhmuctainguyenDAL()
        {
            InitReader();
        }
        protected static void InitReader()
        {
            getFromReader=delegate(SqlDataReader dr)
            {
                DanhmuctainguyenEntity entity = new DanhmuctainguyenEntity();
				entity.PK_iDanhmuctainguyenID = Int16.Parse("0"+dr["PK_iDanhmuctainguyenID"].ToString());
				entity.sTendanhmuctainguyen = dr["sTendanhmuctainguyen"].ToString();
				entity.sTenthumuc = dr["sTenthumuc"].ToString();
                return entity;
            };
        }
        public static DanhmuctainguyenEntity GetOne(Int16 PK_iDanhmuctainguyenID)
        {
            string cmdName = "spDanhmuctainguyen_GetByPK";
            SqlParameter p = new SqlParameter("@PK_iDanhmuctainguyenID", PK_iDanhmuctainguyenID);
            DanhmuctainguyenEntity entity = GetOne(cmdName, p);
            return entity;
        }
        public static List<DanhmuctainguyenEntity> GetAll()
        {
            string cmdName = "spDanhmuctainguyen_Get";
            return GetList(cmdName);
        }
        
        public static int Add(DanhmuctainguyenEntity entity)
        {
            string cmdName = "spDanhmuctainguyen_Insert";
            return Run(cmdName,true,initParams(entity));

        }
        public static bool Edit(DanhmuctainguyenEntity entity)
        {
            string cmdName = "spDanhmuctainguyen_Update";
            return Run(cmdName,false,initParams(entity))>0;
        }
        public static bool Remove(Int16 PK_iDanhmuctainguyenID)
        {
            string cmdName = "spDanhmuctainguyen_Delete";
            SqlParameter p = new SqlParameter("@PK_iDanhmuctainguyenID", PK_iDanhmuctainguyenID);
            return Run(cmdName,false,p)>0;
        }
        #region private
        private static SqlParameter[] initParams(DanhmuctainguyenEntity entity)
        {
            SqlParameter[] p = new SqlParameter[3];
			p[0] = new SqlParameter("@PK_iDanhmuctainguyenID", entity.PK_iDanhmuctainguyenID);
			p[1] = new SqlParameter("@sTendanhmuctainguyen", entity.sTendanhmuctainguyen);
			p[2] = new SqlParameter("@sTenthumuc", entity.sTenthumuc);
            return p;
        }
        #endregion
       
    }
}